#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2020/6/17 0017 19:54
# @Author  : wzy
# @Site    : 
# @File    : cmp_json.py
# @Software: PyCharm

import configparser
import json
import json_tools
from Util.operate_json import operateJson
from Util.operate_pathUrll import pathinfo
base = pathinfo

def json_cmp(json1,json2):
    '''
    :param json1: JSON1
    :param json2: JSON2    JSON2 与 JSON1格式做对比
    :return:
    '''
    if isinstance(json1, dict):
        for key in json2:
            if key not in json1:
                print("json1不存在这个key" + str(key))
        for key in json1:
            if key in json2:
                print("对比完成")
                # 递归
                json_cmp(json1[key],json2[key])
            else:
                json1[key] = ["json2 不存在这个key"]
    elif isinstance(json1, list):
        if len(json1) != len(json2):
            print("json1 '{}' 与 json2'{}' 不相等 ".format(len(json1),len(json2)))
        for json_list1, json2_list1 in zip(sorted(json1), sorted(json2)):
            json_cmp(json_list1,json2_list1)
    else:
        if str(json1) != str(json2):
            print("json != json"+str(json1)+str(json2))

if __name__ == '__main__':
    dict1 = operateJson.get_json_value("app","test.json")
    dict2 = operateJson.get_json_value("app","test.json")
    print(dict1)
    print(dict2)
    xx = {"111": None, "23456": {"22222": 9999, "33333": "0000", "list": ["3333", "4444", "111"]}}
    yy = {"111": None, "23456": {"22222": 9999, "33333": "0000", "list": ["111", "3333", "4444"]}}
    json_cmp(dict1,dict2)
